package com.newcapce.network;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        //此处连接服务器(发起网络连接)
        Socket socket = new Socket("192.168.0.127",11111);
        DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        new Thread(){
            @Override
            public void run() {
                while (true){
                    String str = null;
                    try {
                        str = dataInputStream.readUTF();
                        System.out.println("客户端收到"+str);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
            }
        }.start();
//        String str = dataInputStream.readUTF();
//        System.out.println(str);

        Scanner scanner = new Scanner(System.in);
        while(true){
            String sendStr = scanner.nextLine();
            dataOutputStream.writeUTF(sendStr);
            dataOutputStream.flush();
        }

    }
}
